package org.moore.view;

import org.moore.utils.Data;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

import static org.moore.utils.Button.getjButton;

public class LoginJLabel extends JLabel {
    /**
	 * 
	 */
	private static final long serialVersionUID = -5921037698832592570L;
	// 创建账号输入框
    private final JTextField accText = new JTextField();
    // 创建密码输入框
    private final JPasswordField pwdText = new JPasswordField();
    // 创建验证码输入框
    private final JTextField checkText = new JTextField();
    // 创建随机数按钮
    private final JButton checkNum;
    // 创建登录按钮
    private final JButton yesButton;
    // 创建返回按钮
    private final JButton backButton;
    // 创建字体
    private final Font font = new Font("微软雅黑",Font.BOLD,30);

    public JTextField getAccText() {
        return accText;
    }

    public JPasswordField getPwdText() {
        return pwdText;
    }

    public JTextField getCheckText() {
        return checkText;
    }

    public LoginJLabel() {
        // 设置账号输入框并添加
        accText.setBounds(250,175,200,50);
        accText.setFont(font);
        this.add(accText);
        // 设置密码输入框并添加
        pwdText.setBounds(250,275,200,50);
        pwdText.setFont(font);
        this.add(pwdText);
        // 设置验证码输入框
        checkText.setBounds(250,375,200,50);
        checkText.setFont(font);
        this.add(checkText);
        // 绘制随机数按钮
        checkNum = getjButton(null, new Font("宋体", Font.PLAIN, 25));
        // 创建随机数
        Random random = new Random();
        // 设置随机数
        int num = random.nextInt(10000);
        checkNum.setText(Integer.toString(num));
        checkNum.setForeground(Color.BLACK);
        checkNum.setBounds(300, 430, 100, 30);
        this.add(checkNum);
        // 设置登录按钮
        yesButton = getjButton(Data.BUTTON_ICON, Data.FONT);
        yesButton.setBounds(120,480,150,150);
        yesButton.setText("登录");
        this.add(yesButton);
        // 设置返回按钮
        backButton = getjButton(Data.BUTTON_ICON, Data.FONT);
        backButton.setBounds(320,480,150,150);
        backButton.setText("返回");
        this.add(backButton);
    }

    public JButton getYesButton() {
        return yesButton;
    }

    public JButton getBackButton() {
        return backButton;
    }

    public JButton getCheckNum() {
        return checkNum;
    }
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        // 使用g2d绘制以修复抗锯齿
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        // 绘制背景
        g2d.drawImage(Data.WELCOME_BACKGROUND,0,0,this.getWidth(),this.getHeight(),null);
        // 绘制标题图片
        g2d.drawImage(Data.TITLE_IMAGE, 480, 50, 1000, 130, null);
        // 设置字体
        g2d.setFont(font);
        // 绘制提示文字
        g2d.drawString("用户登录",230,100);
        // 绘制账号文字
        g2d.drawString("账       号",100,210);
        // 绘制密码文字
        g2d.drawString("密       码",100,310);
        // 绘制验证码文字
        g2d.drawString("验  证  码",100,410);
    }
}
